﻿using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using VietTrips.Domain.Models;

namespace VietTrips.Domain.Contexts
{
    class EntitiesContexts : DbContext
    {

        public EntitiesContexts()
            : base("DefaultConnection")
        {
            
        }

        public virtual DbSet<Activity> Activities { get; set; }
        public virtual DbSet<ActivityDetail> ActivityDetails { get; set; }
        public virtual DbSet<ActivityType> ActivityTypes { get; set; }
        public virtual DbSet<Address> Addresses { get; set; }
        public virtual DbSet<Area> Areas { get; set; }
        public virtual DbSet<Booking> Bookings { get; set; }
        public virtual DbSet<Criterion> Criteria { get; set; }
        public virtual DbSet<Hotel> Hotels { get; set; }
        public virtual DbSet<Image> Images { get; set; }
        public virtual DbSet<Movement> Movements { get; set; }
        public virtual DbSet<Place> Places { get; set; }
        public virtual DbSet<Rating> Ratings { get; set; }
        public virtual DbSet<Review> Reviews { get; set; }
        public virtual DbSet<Tour> Tours { get; set; }
        public virtual DbSet<TourAgency> TourAgencies { get; set; }
        public virtual DbSet<Traveler> Travelers { get; set; }
        public virtual DbSet<Trip> Trips { get; set; }
        public virtual DbSet<TripGroup> TripGroups { get; set; }
        public virtual DbSet<UserProfile> UserProfiles { get; set; }
        public virtual DbSet<VehicleType> VehicleTypes { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            /*modelBuilder.Entity<Activity>()
                .HasMany(e => e.ActivityDetails)
                .WithRequired(e => e.Activity)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Booking>()
                .Property(e => e.Status)
                .IsFixedLength();

            modelBuilder.Entity<Booking>()
                .Property(e => e.PaymentMethod)
                .IsFixedLength();

            modelBuilder.Entity<Criterion>()
                .HasMany(e => e.Ratings)
                .WithRequired(e => e.Criterion)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Image>()
                .HasMany(e => e.Activities)
                .WithOptional(e => e.Image)
                .HasForeignKey(e => e.FeaturedImageId);

            modelBuilder.Entity<Image>()
                .HasMany(e => e.Tours)
                .WithOptional(e => e.Image)
                .HasForeignKey(e => e.FeaturedImageId);

            modelBuilder.Entity<Review>()
                .Property(e => e.LastModified)
                .IsFixedLength();

            modelBuilder.Entity<Review>()
                .HasMany(e => e.Ratings)
                .WithRequired(e => e.Review)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Tour>()
                .HasMany(e => e.Reviews)
                .WithRequired(e => e.Tour)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Tour>()
                .HasMany(e => e.Trips)
                .WithRequired(e => e.Tour)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TourAgency>()
                .Property(e => e.Website)
                .IsFixedLength();

            modelBuilder.Entity<TourAgency>()
                .Property(e => e.RequestStatus)
                .IsFixedLength();

            modelBuilder.Entity<TourAgency>()
                .HasMany(e => e.Addresses)
                .WithRequired(e => e.TourAgency)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TourAgency>()
                .HasMany(e => e.Tours)
                .WithRequired(e => e.TourAgency)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Traveler>()
                .Property(e => e.IDCard)
                .IsFixedLength();

            modelBuilder.Entity<Trip>()
                .HasMany(e => e.ActivityDetails)
                .WithRequired(e => e.Trip)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Trip>()
                .HasMany(e => e.Travelers)
                .WithRequired(e => e.Trip)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<TripGroup>()
                .Property(e => e.LastModified)
                .IsFixedLength();

            modelBuilder.Entity<UserProfile>()
                .Property(e => e.Phone)
                .IsUnicode(false);

            modelBuilder.Entity<UserProfile>()
                .HasMany(e => e.Bookings)
                .WithRequired(e => e.UserProfile)
                .HasForeignKey(e => e.CustomerId)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<VehicleType>()
                .HasMany(e => e.Movements)
                .WithRequired(e => e.VehicleType)
                .HasForeignKey(e => e.VehicleTypeId)
                .WillCascadeOnDelete(false);*/
        }
    }
}
